package com.lm.ledger.action;

import java.util.List;
import java.util.Map;

import com.lm.ledger.dao.LedgerDao;
import com.lm.ledger.exception.LedgerException;
import com.lm.ledger.service.TransactionService;
import com.lm.ledger.service.TransactionServiceImp;
import com.lm.ledger.utill.Account;
import com.lm.ledger.utill.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class TrxAction extends ActionSupport{


	TransactionService service = new TransactionServiceImp();
	private String formId = null;
	private String locId = null;
	private String locName = null;
	private Double amount;
	private String reason = null;
	private String itemName = null;
	private String txDate = null;
	private String retDate = null;
	private Double interestAmount;
	private String personId = null;
	private String personName = null;
	private String narration = null;
	private String txTye = null;
	private String mode = null;
	private String authId = null;
	private String authName = null;
	private String status = null;
	private String role;
	List locations ;
	
	public String getAuthName() {
		return authName;
	}
	public void setAuthName(String authName) {
		this.authName = authName;
	}
	public String getPersonName() {
		return personName;
	}
	public void setPersonName(String personName) {
		this.personName = personName;
	}
	public String getLocName() {
		return locName;
	}
	public void setLocName(String locName) {
		this.locName = locName;
	}
	public List getLocations() {
		return locations;
	}
	public void setLocations(List locations) {
		this.locations = locations;
	}
	public String getRole() {
		System.out.println("getRole ..........");
		return role;
	}
	public void setRole(String role) {
		System.out.println("setRole ..........");
		this.role = role;
	}
	public String getFormId() {
		return formId;
	}
	public void setFormId(String formId) {
		this.formId = formId;
	}
	public String getLocId() {
		return locId;
	}
	public void setLocId(String locId) {
		this.locId = locId;
	}
	public Double getAmount() {
		return amount;
	}
	public void setAmount(Double amount) {
		this.amount = amount;
	}
	public String getReason() {
		return reason;
	}
	public void setReason(String reason) {
		this.reason = reason;
	}
	public String getItemName() {
		return itemName;
	}
	public void setItemName(String itemName) {
		this.itemName = itemName;
	}
	public String getTxDate() {
		return txDate;
	}
	public void setTxDate(String txDate) {
		this.txDate = txDate;
	}
	public String getRetDate() {
		return retDate;
	}
	public void setRetDate(String retDate) {
		this.retDate = retDate;
	}
	public Double getInterestAmount() {
		return interestAmount;
	}
	public void setInterestAmount(Double interestAmount) {
		this.interestAmount = interestAmount;
	}
	public String getPersonId() {
		return personId;
	}
	public void setPersonId(String personId) {
		this.personId = personId;
	}
	public String getNarration() {
		return narration;
	}
	public void setNarration(String narration) {
		this.narration = narration;
	}
	public String getTxTye() {
		return txTye;
	}
	public void setTxTye(String txTye) {
		this.txTye = txTye;
	}
	public String getMode() {
		return mode;
	}
	public void setMode(String mode) {
		this.mode = mode;
	}
	public String getAuthId() {
		return authId;
	}
	public void setAuthId(String authId) {
		this.authId = authId;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	
	public User getUser(){
		ActionContext  context = ActionContext.getContext();
		Map session = context.getSession();
		
		User user = (User) session.get("USER");
		return user;
	}
	
	public Account getAccountDetail(){
		String stat = getStatus();
		String perId = getPersonId();
		if(perId==null || "".equals(perId)){
			perId = getUser().getUserId().toString();
		}
		System.out.println("stsus getAccountDetail  "+stat);
		if(stat==null || "".equals(stat)){
			System.out.println("stsus getAccountDetail  "+stat);
			stat = "N";
		}if(stat=="false" || "false".equalsIgnoreCase(stat)){
			stat = "N";
		}if(stat=="true" || "true".equalsIgnoreCase(stat)){
			stat = "Y";
		}
		if(getTxDate()!=null){
			setTxDate(getTxDate().substring(0, 10));
		}if(getRetDate()!=null){
			setRetDate(getRetDate().substring(0, 10));
		}
		System.out.println("getTxDate ----"+getTxDate());
		Account account = new Account();
		account.setAmount(getAmount());
		account.setFormId(getFormId());
		account.setLocId(getLocId());
		account.setLocName(getLocName());
		account.setReason(getReason());
		account.setAuthId(getAuthId());
		account.setInterestAmount(getInterestAmount());
		account.setItem(getItemName());
		account.setMode(getMode());
		account.setNarration(getNarration());
		account.setPersonId(perId);
		account.setRetDate(getRetDate());
		account.setStatus(stat);
		account.setTxTye(getTxTye());
		account.setTxDate(getTxDate());
		account.setRole(getRole());
		account.setAuthName(getAuthName());
		account.setPersonName(getPersonName());
		
		
		System.out.println("getAccountDetail form id " +account.getFormId());
		return account;
	}
	
	public void setValues(Account acc){
		setFormId(acc.getFormId());
		setLocId(acc.getLocId());
		setLocName(acc.getLocName());
		setAmount(acc.getAmount());
		setReason(acc.getReason());
		setItemName(acc.getItem());
		setTxDate(acc.getTxDate());
		setRetDate(acc.getRetDate());
		setInterestAmount(acc.getInterestAmount());
		setPersonId(acc.getPersonId());
		setPersonName(acc.getPersonName());
		setNarration(acc.getNarration());
		setTxTye(acc.getTxTye());
		setMode(acc.getMode());
		setAuthId(acc.getAuthId());
		if("N".equalsIgnoreCase(acc.getStatus())){
			setStatus("false");
		}else if("Y".equalsIgnoreCase(acc.getStatus())){
			setStatus("true");
		}
		//setStatus(acc.getStatus());
		setAuthName(acc.getAuthName());
		
			setLocations(service.getLocations(getUser().getUserId()));
		
		
		System.out.println("form id === "+getFormId());
		System.out.println("loc id === "+getLocId());
		System.out.println("reason id === "+getReason());
		System.out.println("amount id === "+getAmount());
	}
}
